// 方式一
// 嵌套循环
// 时间：120ms 6%
function longestCommonPrefix(strs) {
  if (strs.length < 1) {
    return "";
  }
  const sortStrs = strs.sort((a, b) => a.length - b.length);
  const minStr = sortStrs[0];
  const restStrs = sortStrs.slice(1);
  let res = "";
  for (let n = 0; n < minStr.length; n++) {
    console.log(minStr[n]);
    if (is(minStr[n], n, restStrs)) {
      res += minStr[n];
    } else {
      break;
    }
  }
  return res;

  function is(s, n, strs) {
    for (let index = 0; index < strs.length; index++) {
      const element = strs[index];
      if (s !== element[n]) {
        return false;
      }
    }
    return true;
  }
}
console.log(longestCommonPrefix([]));
